#ifndef _PRODUCTION_BURN_UID_H_
#define _PRODUCTION_BURN_UID_H_

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "InCommon.h"

#define DEF_BURN_UID_IP        "192.168.7.11" //server address
#define DEF_BURN_UID_PORT      20005          //server port
#define DEF_BURN_UID_STR_RET "{\"ap_name\":\"%s\", \"version\":\"%s\", \"wifi\":\"%s\", \"video\": \"ok\", \"tfcard\":\"ok\", \"serial\":\"ok\", \"key\":\"key_ok\"}"

#if CMAKE_CHZH_PRODUCT
#define DEF_BURN_UID_AP_NAME "CHZH_"
#else
#error "no this device AP name"
#endif

typedef enum
{
    COMMAND_TYPES_AUTO_BURN_UID_REQ         = 0x10, //auto burn uuid req
    COMMAND_TYPES_AUTO_BURN_UID_RESP        = 0x11, //auto burn uuid resp
    COMMAND_TYPES_AUTO_BURN_UID_RESULT_REQ  = 0x12, //auto burn uuid result req
    COMMAND_TYPES_AUTO_BURN_UID_RESULT_RESP = 0x13, //auto burn uuid result resp
}ECommands;

//tcp header
typedef struct
{
    int command_type; //ECommands
    char protocol_flag[4];//"JTCP"
    int data_size;    //recv and send date struct lenght
}StBurnUidHeader,*pStBurnUidHeader;

//device auto burn uuid req
typedef struct
{
    char  wireless_mac[20];//wifi mac
    char  system_version[16];//version
    char  mcu_version[16]; //mcu version
    char  device_product_type[40];//product_name
    char  reserver[4]; //retain
    char  test_result[512]; //json rsult
}StBurnUidReq,*pStBurnUidReq;

typedef enum
{
    SUCCESS                   = 0x00, //成功
    MODEL_UNSUPPORT           = 0x01, //产品号服务器不支持
    UID_NONE                  = 0x02, //服务器没有可用UID
    ALREADY_BURN              = 0x03, //服务器里相同UID已烧录过
    SYSTEM_ERROR              = 0x04  //服务器系统错误
}EnBurnUidRetCode;

//server auto burn uuid resp
typedef struct
{
    int  result; //0-ok, 1-failed refrence EnBurnUidRetCode
    char device_id[24];
    char encrypt_mac[20];
    char DeviceSecret[40];//only ali esp8266 is valid
    int  wifi__expert_signal_db;//wifi 期望的信号质量
}StBurnUidResp,*pStBurnUidResp;


//设备上报服务器设置uid 结果
typedef struct
{
    int burn_result;//0-ok, 1-failed
    char device_id[24];
    char encrypt_mac[20];
    char DeviceSecret[40];//only ali esp8266 is valid
    char reserverd[8];//保留
}StBurnUidResultReq;

//服务器回应烧号结果，并下发是否自动升级，升级地址固定
typedef struct
{
    int  result; //0-ok, 1-failed refrence RET_CODE
    int  auto_upgrade;//1-auto upgrade,0-no upgrade 是否自动升级
    char upgrade_addr[128];//如果不是空则表示新地址，为空系统采用默认局域网地址
    char reserverd[8];//保留
}StBurnUidResultResp;

#endif
